#include <system.h>

void react(char com[255])
{
	puts("\n");
	
	if (com[0] == 's' & com[1] == 't' & com[2] == 'o' & com[3] == 'p' & com[4] == '\0')
	{
		stop();
		return;
	}
	
	if (com[0] == 'h' & com[1] == 'e' & com[2] == 'l' & com[3] == 'p' & com[4] == '\0')
	{
		help();
		return;
	}
	
	if (com[0] == 'a' & com[1] == 'b' & com[2] == 'o' & com[3] == 'u' & com[4] == 't' & com[5] == '\0')
	{
		about();
		return;
	}
	
	if (com[0] == 'c' & com[1] == 'l' & com[2] == 's' & com[3] == '\0')
	{
		cls();
		return;
	}
	
	puts("Inavlid command or file name\n");
	return;
}

void *memcpy(void *dest, const void *src, size_t count)
{
    const char *sp = (const char *)src;
    char *dp = (char *)dest;
    for(; count != 0; count--) *dp++ = *sp++;
    return dest;
}

void *memset(void *dest, char val, size_t count)
{
    char *temp = (char *)dest;
    for( ; count != 0; count--) *temp++ = val;
    return dest;
}

unsigned short *memsetw(unsigned short *dest, unsigned short val, size_t count)
{
    unsigned short *temp = (unsigned short *)dest;
    for( ; count != 0; count--) *temp++ = val;
    return dest;
}

size_t strlen(const char *str)
{
    size_t retval;
    for(retval = 0; *str != '\0'; str++) retval++;
    return retval;
}

unsigned char inportb (unsigned short _port)
{
    unsigned char rv;
    __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
    return rv;
}

void outportb (unsigned short _port, unsigned char _data)
{
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

void about()
{
	puts("coded by Cboomf\n");
	puts("code available as open source from code.google.com\n\n");
}

void stop()
{
	cli();
	puts("Stopping everything and nothing else will work now LOL");
	while(1)
	{
	
	}
}

void main()
{
    int i;

	cli();
	
    gdt_install();
    idt_install();
    isrs_install();
    irq_install();
    init_video();
    timer_install();
    keyboard_install();

	settextcolor('9','0');
    puts("CBMF");
	settextcolor_default();
	puts(" Doors Kernel v");
	puts(major);
	putch('.');
	puts(middle);
	putch('.');
	puts(minor);
	puts(" r");
	puts(release);
	putch('\n');
	puts(" > ");

	sti();

//    i = 10 / 0;
//    putch(i);

    while(1)
	{
	}
}
